{extend name="common/adminBase" /}
{block name="body"}
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">

                <div class="layui-card-header">
                    <button class="layui-btn  layui-btn-xs"  onclick="xadmin.open('添加角色','addRole',900,700)" ><i class="layui-icon">&#xe642;</i>添加角色</button>
                </div>
                <div class="layui-card-body ">
                    <table class="layui-table layui-form">
                        <thead>
                        <tr>
                            <th width="70">ID</th>
                            <th>栏目名</th>
                            <th>状态</th>
                            <th>操作</th>
                        </thead>
                        <tbody class="x-cate">
                        {volist name="data" id="v"}
                        <tr cate-id="{$v.id}" fid="{$v.pid}" >
                            <td>{$v.id}</td>
                            <td>
                                <i class="layui-icon x-show" status='true'>&#xe623;</i>
                                <?php echo $v['title']?>
                            </td>
                            <td>
                                {if $v.status == 1}
                                <button class="layui-btn layui-btn-xs">正常</button>
                                {else/}
                                <button class="layui-btn layui-btn-danger layui-btn-xs">关闭</button>
                                {/if}

                            </td>
                            <td class="td-manage">
                                {if $v.id != 1}
                                <a class="layui-btn layui-btn layui-btn-xs"  onclick="xadmin.open('编辑','editRole/?id={$v.id}',800,600)" >
                                    <i class="layui-icon">&#xe642;</i>编辑
                                </a>

                                <button class="layui-btn-danger layui-btn layui-btn-xs"  onclick="member_del({$v.id})" href="javascript:;" >
                                <i class="layui-icon">&#xe640;</i>删除
                                </button>
                                {/if}
                            </td>
                        </tr>
                        {/volist}
                        </tbody>
                    </table>
                </div>
                <div class="layui-card-body ">

                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form'], function(){
        form = layui.form;

    });

    /*用户-删除*/
    function member_del(id){
        layer.confirm('谨慎操作,该操作不可恢复',function(index){
            $.ajax({
                url:'delRole',
                data:{id:id},
                type:'post',
                dataType:'json',
                success:function (res) {
                    if (res.status ==1){
                        layer.msg(res.msg,{icon:1,time:1500},function () {
                            location.reload();
                        });
                    }else{
                        layer.alert(res.msg,function (index) {
                            layer.close(index);
                        })
                    }
                }
            })

        });
    }



    // 分类展开收起的分类的逻辑
    //
    $(function(){
        // $("tbody.x-cate tr[fid!='0']").hide();
        // 栏目多级显示效果
        $('.x-show').click(function () {
            if($(this).attr('status')=='true'){
                $(this).html('&#xe625;');
                $(this).attr('status','false');
                cateId = $(this).parents('tr').attr('cate-id');
                $("tbody tr[fid="+cateId+"]").show();
            }else{
                cateIds = [];
                $(this).html('&#xe623;');
                $(this).attr('status','true');
                cateId = $(this).parents('tr').attr('cate-id');
                getCateId(cateId);
                for (var i in cateIds) {
                    $("tbody tr[cate-id="+cateIds[i]+"]").hide().find('.x-show').html('&#xe623;').attr('status','true');
                }
            }
        })
    })

    var cateIds = [];
    function getCateId(cateId) {
        $("tbody tr[fid="+cateId+"]").each(function(index, el) {
            id = $(el).attr('cate-id');
            cateIds.push(id);
            getCateId(id);
        });
    }

</script>
</body>
{/block}